package com.sanyang.pda.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.sanyang.pda.bean.ScanBean;
import com.sanyang.pda.bean.UnderDetectionBean;
import com.sanyang.pda.view.ScanButView;
import com.wangshen.base.dialog.base.BaseDialog;
import com.wangshen.base.util.ToastUtils;
import com.wangshen.projectbase.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SampleBackDialog extends BaseDialog {
    @BindView(R.id.iv_close)
    ImageView ivClose;

    @BindView(R.id.iv_scan)
    ScanButView ivScan;

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_totel_num)
    TextView tvTotelNum;
    @BindView(R.id.tv_num)
    EditText tvNum;
    @BindView(R.id.tv_cancel)
    TextView tvCancel;
    @BindView(R.id.tv_confirm)
    TextView tvConfirm;
    @BindView(R.id.tv_tray)
    TextView tvTray;
    @BindView(R.id.tv_storage_location)
    TextView tvStorageLocation;
    @BindView(R.id.tv_num_title)
    TextView tvNumTitle;
    private ConfirmClick confirmClick;
    private UnderDetectionBean underDetectionBean;

    public SampleBackDialog(@NonNull Context context, ConfirmClick confirmClick) {
        super(context);
        this.confirmClick = confirmClick;
    }

    @Override
    public void initView() {
        ButterKnife.bind(this);
        ivScan.setScanCallBack(new ScanButView.ScanCallBack() {
            @Override
            public void callBack(ScanBean scanBean) {
                switch (scanBean.getType()) {
                    case 1://商品
                        //tvGoodsName.setText(scanBean.getCode());
                       tvStorageLocation.setText(scanBean.getCode());
                        break;
                    case 2://商品
                        //tvGoodsName.setText(scanBean.getCode());
                        tvStorageLocation.setText(scanBean.getCode());
                        break;
                    case 4://托盘
                        tvTray.setText(scanBean.getCode());
                        break;
                }
            }
        });
    }
    @Override
    public void initData() {

    }

    @Override
    public int getView() {
        return R.layout.dialog_sample_back;
    }

    @OnClick(R.id.iv_close)
    public void onViewClicked() {
        dismiss();
    }

    @OnClick(R.id.tv_cancel)
    public void onTvCancelClicked() {
        dismiss();
    }

    @OnClick(R.id.tv_confirm)
    public void onTvConfirmClicked() {
        if (TextUtils.isEmpty(tvTray.getText().toString())) {
            ToastUtils.showToast(getContext(), getContext().getResources().getString(R.string.tray_cannot_be_empty));
            return;
        }
        if (TextUtils.isEmpty(tvStorageLocation.getText().toString())) {
            ToastUtils.showToast(getContext(), getContext().getResources().getString(R.string.storage_cannot_be_empty));
            return;
        }
        if (confirmClick != null){
            confirmClick.onConfirmClick(tvTray.getText().toString(),tvStorageLocation.getText().toString());
            dismiss();
        }
    }

    public static interface ConfirmClick {
        void onConfirmClick(String pallet,String location);
    }
}
